package kuang.juc.cas;


import java.util.concurrent.atomic.AtomicInteger;

//CAS比较并交换
public class CASDemo {
    public static void main(String[] args) {
        AtomicInteger atomicInteger = new AtomicInteger(2022);

        //是期望值则更新
        System.out.println(atomicInteger.compareAndSet(2022, 2023));
        System.out.println(atomicInteger.get());
        //底仓调用unsafe中的native方法，使用c++操作
        System.out.println(atomicInteger.compareAndSet(2022, 2023));
        System.out.println(atomicInteger.get());
    }
}
